<!doctype html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<body>
	<section class="content-header">
		<h1>
			管理员 <small th:text="(${admin.new}?'新建':'编辑')+'管理员'"></small>
		</h1>
		<ol class="breadcrumb">
			<li>
				<a th:href="@{/dashboard}"><i class="fa fa-dashboard"></i> 首页</a>
			</li>
			<li>
				<a href="javascript:;">系统管理</a>
			</li>
			<li class="active" th:text="(${admin.new}?'新建':'编辑')+'管理员'"></li>
		</ol>
	</section>

	<section class="content">
		<div class="box box-primary">
			<div class="box-header with-border">
				<h3 class="box-title">请输入管理员信息</h3>
			</div>
			<form id="form-admin" class="form-horizontal" th:action="@{/admin/save}" method="post" th:object="${admin}">
				<input type="hidden" name="id" th:value="*{id}" />
				<div class="box-body">
					<div class="form-group">
						<label for="input-username" class="col-sm-2 control-label">账号</label>

						<div class="col-sm-10">
							<input class="form-control" id="input-username" name="username" th:value="*{username}" placeholder="请输入账号"
								type="text" data-bv-notempty="true" data-bv-notempty-message="请填写账号">
						</div>
					</div>
					<div class="form-group">
						<label for="input-password" class="col-sm-2 control-label">密码</label>

						<div class="col-sm-10">
							<input class="form-control" id="input-password" name="newPassword" value=""
								th:placeholder="*{id}==null?'请输入密码':'请输入密码, 留空则不修改'" type="password">
						</div>
					</div>
					<div class="form-group">
						<label for="input-name" class="col-sm-2 control-label">姓名</label>

						<div class="col-sm-10">
							<input class="form-control" id="input-name" placeholder="请输入姓名" name="name" th:value="*{name}" type="text"
								data-bv-notempty="true" data-bv-notempty-message="请填写姓名">
						</div>
					</div>
				</div>
				<div class="box-footer">
					<button type="button" class="btn btn-default" onclick="location.href='#/page/admin'">返回列表</button>
					<button type="submit" class="btn btn-success pull-right">保存</button>
				</div>
			</form>
		</div>
	</section>


	<script type="text/javascript">
		requirejs([ "domReady", "validator" ], function(ready) {
			ready(function() {
				activeMenu("system_admin");
				$("#form-admin").bootstrapValidator().on("success.form.bv", function(e) {
					e.preventDefault();
					var $form = $(e.target);
					var bv = $form.data('bootstrapValidator');
					$.post($form.attr('action'), $form.serialize(), function(result) {
						if (result.success) {
							$.alert({
								title : false,
								content : "保存成功",
								buttons : {
									ok : {
										text : "返回列表",
										action : function() {
											location.href = "#/page/admin";
										}
									}
								}
							});
						} else {
							$.alert({
								title : false,
								content : result.msg
							});
							$form.bootstrapValidator('disableSubmitButtons', false);
						}
					}, "json");
				});
			});
		});
	</script>
</body>
</html>

